$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL +'exchangeCNY/zuan/list',
        datatype: "json",
        colModel: [
            { label: '提现流水id', name: 'id', index: "id", width: 45, key: true,hidden:true },
            { label: '真实姓名', name: 'realName',width: 70},
            { label: '手机号', name: 'mobileNumber',width: 60},
            { label: '类型', name: 'exchangecnyTypeName', width: 45},
            { label: '金额', name: 'amount',width: 45},
            { label: '收款账户', name: 'receiveAccount',width: 70},
            { label: '时间', name: 'createTime',width: 70},
            { label: '状态', name: 'exchangeStatusName', width: 40}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.result",
            page: "page.pageNo",
            total: "page.totalPages",
            records: "page.total"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el:'#exchangeCNY',
    data:{
        q:{
            keyword: null
        },
        reason:false,
        showList: true,
        info:{
            id:null,
            reason:null
        }

    },
    methods: {
        query: function () {
            vm.reload();
        },
        successExchangeCNY: function () {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            $.ajax({
                type: "POST",
                url: baseURL + "exchangeCNY/zuan/successExchangeCNY",
                contentType: "application/json",
                data: JSON.stringify({id:id}),
                success: function(r){
                    if(r.code === 'success'){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.message);
                    }
                }
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'keyword': vm.q.keyword},
                page:page
            }).trigger("reloadGrid");
        },
        refuse:function () {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.info.id = id;
            layer.open({
                type: 1,
                btn: ['提交','取消'], //按钮
                area: ['420px', '240px'], //宽高
                offset: '100px',
                content: $('#reason'),
                yes:function (index, layero) {
                    $.ajax({
                        type: "POST",
                        url: baseURL + "exchangeCNY/zuan/refuseExchangeCNY",
                        contentType: "application/json",
                        data: JSON.stringify(vm.info),
                        success: function(r){
                            if(r.code === 'success'){
                                layer.close(index);
                                alert('操作成功', function(){
                                    vm.reload();
                                });
                            }else{
                                alert(r.message);
                            }
                        }
                    });
                }
            });
        }
    }
});

